<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Environment Access
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot125.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot124.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot127.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc274">20.2</A>&nbsp;&nbsp;Environment Access</H2><UL>
<LI><A HREF="umsroot126.html#toc150">Command Line Arguments</A>
<LI><A HREF="umsroot126.html#toc151">Environment Variables</A>
<LI><A HREF="umsroot126.html#toc152">Exiting ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP></A>
<LI><A HREF="umsroot126.html#toc153">Time and Date</A>
<LI><A HREF="umsroot126.html#toc154">Host Computer</A>
<LI><A HREF="umsroot126.html#toc155">Calling C Functions</A>
</UL>

A number of predicates and global flags is provided to get more or less
useful information from the operating system environment.
<A NAME="toc150"></A>
<H3 CLASS="subsection"><A NAME="htoc275">20.2.1</A>&nbsp;&nbsp;Command Line Arguments</H3>
Arguments provided on the UNIX (or DOS) command line are accessed by the builtins
<A NAME="@default1100"></A>
<A NAME="@default1101"></A>
<A NAME="@default1102"></A>
<A HREF="../bips/kernel/opsys/argc-1.html"><B>argc/1</B></A><A NAME="@default1103"></A> which gives the number of command line arguments (including
the command name itself) and <A HREF="../bips/kernel/opsys/argv-2.html"><B>argv/2</B></A><A NAME="@default1104"></A> which returns a requested positional
argument in string form. If the first argument of <B>argv/2</B> is the atom
all, then a list of all command line arguments is returned.<BR>
<BR>
<A NAME="toc151"></A>
<H3 CLASS="subsection"><A NAME="htoc276">20.2.2</A>&nbsp;&nbsp;Environment Variables</H3>
On UNIX, environment variables are another way to pass information to the
ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> process. Their string value can be read using <A HREF="../bips/kernel/opsys/getenv-2.html"><B>getenv/2</B></A><A NAME="@default1105"></A>:
<A NAME="@default1106"></A>
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: getenv('HOME', Home).

Home = "/usr/octopus"
yes.
</PRE></BLOCKQUOTE>
The environment variables available on Window is version dependent, and is
not a recommended method of passing information.<BR>
<BR>
<A NAME="toc152"></A>
<H3 CLASS="subsection"><A NAME="htoc277">20.2.3</A>&nbsp;&nbsp;Exiting ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP></H3>
When ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> is exited, it can give a return code to the operating system.
This is done by using <A HREF="../bips/kernel/opsys/exit-1.html"><B>exit/1</B></A><A NAME="@default1107"></A>. It exits ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> and returns its integer
argument to the operating system.
<A NAME="@default1108"></A>
<A NAME="@default1109"></A>
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: exit(99).
csh% echo $status
99
</PRE></BLOCKQUOTE>
Note that <B>halt</B> is equivalent to <B>exit(0)</B>.<BR>
<BR>
<A NAME="toc153"></A>
<H3 CLASS="subsection"><A NAME="htoc278">20.2.4</A>&nbsp;&nbsp;Time and Date</H3>
The current date can be obtained in the form of a UNIX date string:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: date(Today).

Today = "Tue May 29 20:49:39 1990\n"
yes.
</PRE></BLOCKQUOTE>
The library <B>calendar</B> contains a utility predicate to convert
this string into a Prolog structure.
Another way to access the current time and date is the global flag
<B>unix_time</B>. It returns the current time in the traditional UNIX
measure, i.e. in seconds since 00:00:00 GMT Jan 1, 1970:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: get_flag(unix_time, Now).

Now = 644008011
yes.
</PRE></BLOCKQUOTE>
Other interesting timings concern the resource usage of the running ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>.
The <A HREF="../bips/kernel/env/statistics-2.html"><B>statistics/2</B></A><A NAME="@default1110"></A> builtin gives three different times, the user
cpu time, the system cpu time and the elapsed real time since
the process was started (all in seconds):
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
[eclipse 1]: statistics(times, Used).

Used = [0.916667, 1.61667, 2458.88]
yes.
</PRE></BLOCKQUOTE>
The first figure (user cpu time) is the same as given by <A HREF="../bips/kernel/opsys/cputime-1.html"><B>cputime/1</B></A><A NAME="@default1111"></A>.<BR>
<BR>
<A NAME="toc154"></A>
<H3 CLASS="subsection"><A NAME="htoc279">20.2.5</A>&nbsp;&nbsp;Host Computer</H3>
Access to the name and unique identification of the host computer where
the system is running can be obtained by the two global flags
<A NAME="@default1112"></A>
<A NAME="@default1113"></A>
<A NAME="@default1114"></A>
<B>hostname</B> and <B>hostid</B>, accessed via <A HREF="../bips/kernel/env/get_flag-2.html"><B>get_flag/2</B></A><A NAME="@default1115"></A> or
<A HREF="../bips/kernel/env/env-0.html"><B>env/0</B></A><A NAME="@default1116"></A>. These flags might not be available on all machines,
<A HREF="../bips/kernel/env/get_flag-2.html"><B>get_flag/2</B></A><A NAME="@default1117"></A> fails in these cases.<BR>
<BR>
<A NAME="toc155"></A>
<H3 CLASS="subsection"><A NAME="htoc280">20.2.6</A>&nbsp;&nbsp;Calling C Functions</H3>
Other data may be obtained with the predicate <A HREF="../bips/kernel/externals/call_c-2.html"><B>call_c/2</B></A><A NAME="@default1118"></A>
which allows to call directly any C function which is
linked to the Prolog system.
Functions which are not linked can be loaded dynamically with the
<A HREF="../bips/kernel/externals/load-1.html"><B>load/1</B></A><A NAME="@default1119"></A> predicate.<BR>
<BR>
<HR>
<A HREF="umsroot125.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot124.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot127.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
